package com.definity.toolkit.ui.util;

import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.List;

public class BasicFileFilter implements FileFilter {

	private final boolean folder;
	private final List<String> extensions;

	public BasicFileFilter(String... extensions) {
		this(true, extensions);
	}
	
	public BasicFileFilter(boolean folder, String... extensions) {
		this.folder = folder;
		this.extensions = Arrays.asList(extensions);
	}

	@Override
	public boolean accept(File file) {
		if (file.isDirectory())
			return folder;
		
		String name = file.getName();
		String extension = name.substring(name.lastIndexOf(".") + 1);
		
		return extensions.contains(extension);
	}

}
